/*
 * Copyright 2008 Johnny Jian
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.getris.dialog

import groovy.swing.SwingBuilder
import static java.awt.BorderLayout.*
import static java.awt.FlowLayout.*
import static java.awt.event.KeyEvent.*
import javax.swing.WindowConstants

dialog = new SwingBuilder().dialog(
    title: 'High Scores',
    owner: frame,
    resizable: false,
    modal: true,
    pack: true,
    defaultCloseOperation: WindowConstants.DISPOSE_ON_CLOSE
) {
    panel(border: emptyBorder(10)) {
        borderLayout()
        panel(constraints: CENTER) {
            gridBagLayout()
            label(text: 'Rank', constraints: gbc(gridx: 0, gridy: 0, ipadx: 20, ipady: 5))
            label(text: 'Name', constraints: gbc(gridx: 1, gridy: 0, ipadx: 80))
            label(text: 'Score', constraints: gbc(gridx: 2, gridy: 0, ipadx: 30))
            tetris.highScores.eachWithIndex { item, row ->
                label(text: row + 1, constraints: gbc(gridx: 0, gridy: row + 1, ipadx: 20, ipady: 5))
                label(text: item.name, constraints: gbc(gridx: 1, gridy: row + 1, ipadx: 80))
                label(text: item.score, constraints: gbc(gridx: 2, gridy: row + 1, ipadx: 30))
            }
            panel(constraints: gbc(gridx: 0, gridy: 11))
        }
        panel(constraints: SOUTH) {
            flowLayout(alignment: RIGHT)
            button(text: 'Reset', mnemonic: VK_R, preferredSize: [80, 25], actionPerformed: {
                tetris.highScores.reset()
                dialog.dispose()
            })
            closeButton = button(text: 'Close', mnemonic: VK_C, preferredSize: [80, 25], actionPerformed: {
                dialog.dispose()
            })
        }
    }
}
dialog.locationRelativeTo = null
closeButton.requestFocus()
dialog.visible = true
